
using System;
using System.Linq;
using Csla;
using Csla.Data;

namespace HousingInfo.Library
{ 
	public partial class HousingTypeBOList : Csla.BusinessListBase<HousingTypeBOList, HousingTypeBO>
	{

		#region Authorization Rules

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of HousingTypeBOList
			//AuthorizationRules.AllowCreate(typeof(HousingTypeBOList), "HousingTypeBOListCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(HousingTypeBOList), "HousingTypeBOListEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(HousingTypeBOList), "HousingTypeBOListDeleteGroup"));
		}
		#endregion //Authorization Rules

        #region Ham lay 5 tin nha dat moi nhat
        #region Ham
        public static HousingTypeBOList GetHouseType_ByNum(int number)
        {
            return DataPortal.Fetch<HousingTypeBOList>(new FilterCriteriaGetHouseType_ByNumber(number));
        }
        #endregion //End ham lay tung loai danh muc

        #region khai bao tham so
        private class FilterCriteriaGetHouseType_ByNumber
        {
            public int soluong;
            public FilterCriteriaGetHouseType_ByNumber(int sl)
            {
                this.soluong = sl;
            }
        }
        #endregion//end khai bao tham so
        #region Data Access - Fetch
        private void DataPortal_Fetch(FilterCriteriaGetHouseType_ByNumber param)
        {
            bool cancel = false;
            OnFetching(ref cancel);
            if (cancel) return;

            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                RaiseListChangedEvents = false;

                this.AddRange(
                    (from row in mgr.DataContext.HousingTypes
                    where row.IsActive == true
                    select HousingTypeBO.GetHousingTypeBO(row.HousingTypeID)).Take(param.soluong)
                );

                RaiseListChangedEvents = true;
            }//using


            //OnFetched();
        }
        #endregion
        #endregion
    }
}
